import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import { vitePluginForArco } from '@arco-plugins/vite-vue';
import configArcoStyleImportPlugin from './config/plugin/arcoStyleImport';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    configArcoStyleImportPlugin(),
    vue(),
    vitePluginForArco({
      style: true,
    }),
  ],
  resolve: {
    alias: [
      {
        find: '@',
        replacement: resolve(__dirname, 'src'),
      },
      {
        find: 'vue',
        replacement: 'vue/dist/vue.esm-bundler.js',
      },
    ],
    extensions: ['.ts', '.js'],
  },
  define: {
    'process.env': {},
  },
  server: {
    port: parseInt(process.env.PORT || '5173'),
    open: true,
    fs: {
      strict: true,
    },
    // 添加代理配置，将API请求转发到后端服务器
    proxy: {
      '/api': {
        target:
          process.env.VITE_API_BASE_URL || 'http://localhost:8070/zscd/admin',
        changeOrigin: true,
        rewrite: (path) => path,
      },
    },
    // 添加historyApiFallback配置，确保SPA刷新时不会404
    historyApiFallback: true,
  },
});
